package com.jch.dm.chapter_21_proxy;

/**
 * @author: Administrator
 * @create: 2020/04/12 11:16
 * 打印类 本人
 **/
public class Printer implements Printable {

    private String name;

    public Printer() {
        heavyJob("Printer的实例生成中");
    }

    public Printer(String name) {
        this.name = name;
        heavyJob("Printer的实例生成中("+name+")");
    }

    private void heavyJob(String s) {
        System.out.print(s);
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(".");
        }
        System.out.println("结束。");
    }

    /**
     * 设置名称
     *
     * @param name
     */
    @Override
    public void setPrinterName(String name) {
        this.name = name;
    }

    /**
     * 获取名称
     *
     * @return name
     */
    @Override
    public String getPrinterName() {
        return name;
    }

    /**
     * 显示文字（打印输出）
     *
     * @param string
     */
    @Override
    public void print(String string) {
        System.out.println("=== "+name+" ===");
        System.out.println(string);
    }
}
